package cn.bytecollege.dao;

import cn.bytecollege.entity.UserManage;

import java.util.List;

public class OrderDao extends BaseDao<UserManage,Integer>{
    /**
     * 查询所有订单
     * zxy
     */
    public List<UserManage> findListByPage(int pageIndex, int pageSize){
        String sql="SELECT order_id,username,user_id_number,user_phone_number,user_start_time,user_end_time,is_vip,user_manage.room_id,true_price,user_state,room_number,room.room_category_id,room_category_name" +
                " FROM USER_MANAGE LEFT JOIN ROOM ON USER_MANAGE.ROOM_ID=ROOM.ROOM_ID LEFT JOIN ROOM_CATEGORY ON ROOM.ROOM_CATEGORY_ID=ROOM_CATEGORY.ROOM_CATEGORY_ID LIMIT ?,?;";
        int index=(pageIndex-1)*pageSize;
        Object[] objects={index,pageSize};
        return helper.executeQuery(sql,UserManage.class,objects);
    }
    /**
     * 统计订单总数
     * zxy
     */
    public int count(){
        String sql="SELECT COUNT(*) FROM USER_MANAGE;";
        return helper.executeScale(sql);
    }
    /**
     * 根据用户名模糊查询订单
     * zxy
     */
    public List<UserManage> findListByName(int pageIndex, int pageSize,String username) {
        String sql="SELECT order_id,username,user_id_number,user_phone_number,user_start_time,user_end_time,is_vip,user_manage.room_id,true_price,user_state,room_number,room.room_category_id,room_category_name FROM USER_MANAGE LEFT JOIN ROOM ON USER_MANAGE.ROOM_ID=ROOM.ROOM_ID LEFT JOIN ROOM_CATEGORY ON ROOM.ROOM_CATEGORY_ID=ROOM_CATEGORY.ROOM_CATEGORY_ID WHERE USERNAME LIKE ? LIMIT ?,?;";
        Integer index=(pageIndex-1)*pageSize;
        Object[] objects={"%"+username+"%",index,pageSize};
        return helper.executeQuery(sql,UserManage.class,objects);
    }
    /**
     * 统计模糊查询订单数
     */
    public int countByName(String username) {
        String sql = "SELECT COUNT(*) FROM USER_MANAGE WHERE USERNAME LIKE ?;";
        return helper.executeScale(sql,"%"+username+"%");
    }
}
